<?php

/**
 * Class teia\webdev\php\core\DisplayableItem
 * Simple core class for displaying items
 *
 * @author Bernardo Quibiana
 * @date created: 20111003
 *
 * @date modified: 20111003
 * @modified: Bernardo Quibiana
 */

// namespace declaration: core Abstract Data Types
namespace teia\webdev\php\core;

//require_once 'Constants.inc';
require_once 'Item.inc';
require_once 'IDisplayableItem.inc';
//require_once 'FunctionPool.inc';

class DisplayableItem extends Item implements IDisplayableItem {

	/*
	 * images
	 */
	protected $thumbnail = null;
	protected $slide_img = null;
	protected $banner_img = null;
	protected $small_img = null;
	protected $medium_img = null;
	protected $large_img = null;

	/*
	 * texts
	 */
	protected $alt_txt;
	protected $details;

	/*
	 * link
	 */
	protected $link;

	/*
	 * html attributes
	 */
	protected $elem_id;
	protected $elem_class;


	/**
	 * Conscrutor
	 * @param String $id
	 * @param String $name
	 * @param String $alt_txt
	 * @param String $medium_img
	 * @param String $link
	 * @param String $elem_id
	 * @param String $elem_class
	 */
	public function __construct($id, $name='', $var_array=NULL) {
		parent::__construct($id, $name);
		
		if ($var_array && is_array($var_array)) {
			$this->setup($var_array);
		}
	}

	public function __get($property) {
		return  $this->$property;
	}

	public function __set($property, $value) {
		return $this->$property = $value;
	}

	public function toString() {
		return FunctionPool::assoc_to_str($this);
	}
	
	/**
	 * Implementation;
	 */
	public function get_thumbnail() {
		if ($this->thumbnail) {
			return $this->thumbnail;
		} else {
			return $this->small_img;
		}
	}

	/**
	 * Implementation;
	 */
	public function get_slide_image() {
		if ($this->slide_img) {
			return $this->slide_img;
		} else {
			return $this->medium_img;
		}
	}

	/**
	 * Implementation;
	 */
	public function get_small_image() {
		if ($this->small_img) {
			return $this->small_img;
		} else {
			return $this->thumbnail;
		}
	}

	/**
	 * Implementation;
	 */
	public function get_medium_image() {
		if ($this->medium_img) {
			return $this->medium_img;
		} else {
			return $this->slide_img;
		}
	}

	/**
	 * Implementation;
	 */
	public function get_large_image() {
		return $this->large_img;
	}

	/**
	 * Implementation;
	 */
	public function get_alt_text(){
		return $this->alt_txt;
	}

	/**
	 * Implementation;
	 */
	public function get_element_id() {
		return $this->elem_id;
	}

	/**
	 * Implementation;
	 */
	public function get_element_class() {
		return $this->elem_class;
	}

	/**
	 * Implementation;
	 */
	public function get_details() {
		return $this->details;
	}

	/**
	 * Implementation;
	 */
	public function generate($context) {
		if ($context) {
			switch ($context) {
				case 'slide': return $this->generate_slide();
				case 'thumbnail': return $this->generate_thumbnail();
				default:
					return $this->generate_page();
			}
		} else {
			
		}
	}
	
	/**
	 * Implemantion;
	 */
	public function display($context) {
		echo $this->generate($context);	
	}
	
	public function get_link() {
		return $this->link;
	}
	
	public function generate_thumbnail() {
		$code = "<div class=\"listing_item\" id=\"$this->elem_id\">\n
					<a  href=\"$this->get_link()\">\n
						<div class=\"slide_img\">\n
							<img src=\"$this->get_thumbnail()\" alt=\"$this->get_alt_text()\" width=\"$THUMBNAIL_WIDTH\" height=\"$THUMBNAIL_HEIGHT\" />\n
						</div>\n
						<div class=\"item_highlight\">
									
						</div>
					</a>\n
				</div>\n";
		return $code;
	}
	
	public function generate_slide() {
		$code = "<div class=\"slide_item\" id=\"$this->elem_id\">\n
					<a  href=\"$this->get_link()\">\n
						<div class=\"slide_img\">\n
							<img src=\"$this->get_slide_image()\" alt=\"$this->get_alt_text()\" width=\"$SLIDE_WIDTH\" height=\"$SLIDE_HEIGHT\" />\n
						</div>\n
					</a>\n
				</div>\n";
		return $code;
	}
	
	public function generate_page() {
		$code = "
				<div class=\"page_item\" id=\"$this->elem_id\">\n
				</div>\n";
		return $code;
	}
} // end of class DisplayableItem

?>